package com.zhongkun.datahome.web.rest;

import java.util.List;
import javax.annotation.Resource;
import javax.validation.Valid;

import com.zhongkun.datahome.common.core.domain.R;
import com.zhongkun.datahome.service.req.IdsBody;
import com.zhongkun.datahome.service.req.cmd.assets.DataAssetsCmd;
import com.zhongkun.datahome.service.req.cmd.assets.UnbindDataAssetsCmd;
import com.zhongkun.datahome.service.req.qry.assets.DataAssetsQry;
import com.zhongkun.datahome.service.res.PageVo;
import com.zhongkun.datahome.service.res.assets.DataAssetsVo;
import com.zhongkun.datahome.service.service.IDataAssetsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhongkun.datahome.common.annotation.Log;
import com.zhongkun.datahome.common.core.controller.BaseController;
import com.zhongkun.datahome.common.enums.BusinessType;

/**
 * 数字资产Controller
 * 
 * @author ruoyi
 * @date 2025-04-14
 */
@RestController
@RequestMapping("/core/assets")
public class DataAssetsController extends BaseController {
    @Resource
    private IDataAssetsService dataAssetsService;


    @ApiOperation("分页查询数字资产列表")
    @PreAuthorize("@ss.hasPermi('core:assets:page')")
    @GetMapping("/page")
    public R<PageVo<DataAssetsVo>> page(DataAssetsQry qry) {
        return R.ok(dataAssetsService.page(qry));
    }

    @ApiOperation("根据房产查询数字资产列表")
    @GetMapping("/listByHouseId")
    public R<List<DataAssetsVo>> listByHouseId(DataAssetsQry qry) {
        return R.ok(dataAssetsService.listByHouseId(qry));
    }

    @ApiOperation("获取数字资产详细信息")
    @PreAuthorize("@ss.hasPermi('core:assets:query')")
    @GetMapping(value = "/{id}")
    public R<DataAssetsVo> getInfo(@PathVariable("id") Long id) {
        return R.ok(dataAssetsService.getInfo(id));
    }


    @ApiOperation("新增数字资产")
    @PreAuthorize("@ss.hasPermi('core:assets:add')")
    @Log(title = "数字资产", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public R<Long> add(@RequestBody @Valid DataAssetsCmd cmd) {
        return R.ok(dataAssetsService.add(cmd));
    }

    @ApiOperation("修改数字资产")
    @PreAuthorize("@ss.hasPermi('core:assets:edit')")
    @Log(title = "数字资产", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public R<Void> edit(@RequestBody @Valid DataAssetsCmd cmd) {
        dataAssetsService.edit(cmd);
        return R.ok();
    }

    @ApiOperation("切换状态")
    @PreAuthorize("@ss.hasPermi('core:assets:switch')")
    @Log(title = "数字资产", businessType = BusinessType.UPDATE)
    @PutMapping("/switch")
    public R<Void> changeStatus(@RequestBody DataAssetsCmd cmd) {
        dataAssetsService.changeStatus(cmd);
        return R.ok();
    }

    @ApiOperation("解绑数字资产")
    @PreAuthorize("@ss.hasPermi('core:assets:unbind')")
    @Log(title = "数字资产", businessType = BusinessType.UPDATE)
    @PutMapping("/unbind")
    public R<Void> unbind(@RequestBody UnbindDataAssetsCmd cmd) {
        dataAssetsService.unbind(cmd);
        return R.ok();
    }

    @ApiOperation("删除数字资产")
    @PreAuthorize("@ss.hasPermi('core:assets:remove')")
    @Log(title = "数字资产", businessType = BusinessType.DELETE)
	@DeleteMapping("/remove")
    public R<Void> remove(@RequestBody IdsBody idsBody) {
        dataAssetsService.remove(idsBody.getIds());
        return R.ok();
    }
}
